Skip to content

[MIOpen] Port LRN kernels from OpenCL to HIP#4887

Merged
BradPepersAMD merged 5 commits intoROCm:developfrom
StreamHPC:EwanC/miope_lrn_kernel_port
Mar 12, 2026
Merged

[MIOpen] Port LRN kernels from OpenCL to HIP#4887
BradPepersAMD merged 5 commits intoROCm:developfrom
StreamHPC:EwanC/miope_lrn_kernel_port

Conversation

@EwanC
Copy link
Contributor

@EwanC EwanC commented Feb 25, 2026

Motivation

Convert LRN MIOpen kernel from OpenCL-C to HIP

Technical Details

  • Removed unused kernel parameter from forward kernels.
  • No equivalent of mad24 from OpenCL-C in HIP, so used __mul24 then add.
  • Had to use manual loop peeling and constexprs to replicate the loop unrolling behavior from the OpenCL compiler.

Test Plan

Tested by running test_lrn and doing a performance comparison.

Test Result

All tests pass on MI210 & MI300 and performance comparison to be sent internally.

Submission Checklist

@EwanC EwanC added project: miopen organization: streamhpc contributors from streamhpc labels Feb 25, 2026
@EwanC EwanC marked this pull request as ready for review March 10, 2026 10:33
@EwanC EwanC requested a review from a team as a code owner March 10, 2026 10:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ports MIOpen’s LRN kernels from OpenCL-C to HIP source kernels and updates the host-side construction/invocation accordingly.

Changes:

  • Replaced MIOpenLRNFwd.cl / MIOpenLRNBwd.cl with HIP equivalents (.cpp) and updated CMake sources.
  • Updated LRN kernel construction to emit new compile-time defines and reference the new kernel filenames.
  • Removed the unused alpha kernel argument from forward invocation and added a couple of HIP math helpers.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
projects/miopen/src/ocl/mloNorm.cpp Switches kernel filenames to .cpp, renames/reshapes compile-time defines, and updates forward/backward construction functions.
projects/miopen/src/ocl/lrn_ocl.cpp Removes unused forward kernel parameter and updates a comment to be backend-agnostic.
projects/miopen/src/kernels/hip_math_ops.hpp Adds device helpers for division/modulo style operations used by HIP kernels.
projects/miopen/src/kernels/MIOpenLRNFwd.cpp Adds HIP implementation of LRN forward kernels (within-channel + across-channels).
projects/miopen/src/kernels/MIOpenLRNFwd.cl Removes OpenCL forward kernel source.
projects/miopen/src/kernels/MIOpenLRNBwd.cpp Adds HIP implementation of LRN backward kernels.
projects/miopen/src/kernels/MIOpenLRNBwd.cl Removes OpenCL backward kernel source.
projects/miopen/src/include/miopen/mlo_internal.hpp Updates LRN construct method signatures to void.
projects/miopen/src/CMakeLists.txt Replaces .cl kernel sources with new .cpp kernel sources.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@MiloLurati MiloLurati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

EwanC added 5 commits March 12, 2026 13:41
Removed unused kernel parameter from forward kernels.

Tested by running `test_lrn` on MI210.
Requires also lifting an if condition out of the loop when specific
conditions are met
* Fix typos in comments
* Change C-style casts for reinterpret cast
* comment about 24-bit range
@EwanC EwanC force-pushed the EwanC/miope_lrn_kernel_port branch from 737e954 to eb13453 Compare March 12, 2026 12:41
@BradPepersAMD BradPepersAMD merged commit 9adbf63 into ROCm:develop Mar 12, 2026
39 checks passed
jovanau pushed a commit to jovanau/rocm-libraries that referenced this pull request Mar 19, 2026
## Motivation

Convert LRN MIOpen kernel from OpenCL-C to HIP

## Technical Details

* Removed unused kernel parameter from forward kernels.
* No equivalent of `mad24` from OpenCL-C in HIP, so used `__mul24` then
add.
* Had to use manual loop peeling and constexprs to replicate the loop
unrolling behavior from the OpenCL compiler.

## Test Plan

Tested by running `test_lrn` and doing a performance comparison.

## Test Result

All tests pass on MI210 & MI300 and performance comparison to be sent
internally.

## Submission Checklist

- [x] Look over the contributing guidelines at
https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
johannes-graner pushed a commit that referenced this pull request Mar 20, 2026
## Motivation

Convert LRN MIOpen kernel from OpenCL-C to HIP

## Technical Details

* Removed unused kernel parameter from forward kernels.
* No equivalent of `mad24` from OpenCL-C in HIP, so used `__mul24` then
add.
* Had to use manual loop peeling and constexprs to replicate the loop
unrolling behavior from the OpenCL compiler.

## Test Plan

Tested by running `test_lrn` and doing a performance comparison.

## Test Result

All tests pass on MI210 & MI300 and performance comparison to be sent
internally.

## Submission Checklist

- [x] Look over the contributing guidelines at
https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants